//
//  MeViewController.m
//  OCDome
//
//  Created by 李含文 on 2020/7/30.
//  Copyright © 2020 李含文. All rights reserved.
//

#import "MeViewController.h"
#import "UITabBar+HWBadge.h"
#import "HWAddressSelectionViewController.h"

@interface MeViewController ()
/* <#name#> */
@property (nonatomic, assign) BOOL isshow;
/* <#name#> */
@property (nonatomic, assign) NSInteger index;
/* <#name#> */
@property (nonatomic, strong) HWAddressSelectionViewController *vc;

/// <#name#>
@property (nonatomic, strong) UIView *bgView;
@end

@implementation MeViewController


- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        _bgView.backgroundColor = UIColor.redColor;
    }
    return _bgView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"我";
    self.index = 1;
    [self.view addSubview:self.bgView];
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    if (self.bgView.layer.cornerRadius != 4) {
        self.bgView.layer.cornerRadius = 4;
        self.bgView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
        self.bgView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移2，y向下偏移6，默认(0, -3),这个跟shadowRadius配合使用
        self.bgView.layer.shadowOpacity = 0.3;//阴影透明度，默认0
        self.bgView.layer.shadowRadius = 4;//阴影半径，默认3
        self.bgView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight|UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(self.bgView.layer.cornerRadius, self.bgView.layer.cornerRadius)].CGPath;//参数依次为大小，设置四个角圆角状态，圆角曲度  设置阴影路径可避免离屏渲染
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [HWAddressSelectionViewController show:^(HWAddressProvinceModel * _Nonnull province, HWAddressCityModel * _Nonnull city) {
        NSLog(@"%@-%@", province.name, city.title);
    }];
//    [self presentViewController:[HWAddressSelectionViewController new] animated:NO completion:nil];
    self.isshow = !self.isshow;
    if (self.isshow) {
        self.index++;
        [self showBadge];
    } else {
        [self.tabBarController.tabBar hw_hiddenBadgeWithIndex:2 animation:NO];
    }
}
- (void)showBadge {
    self.tabBarController.tabBar.hw_badgeView.layer.borderColor = UIColor.whiteColor.CGColor;
    self.tabBarController.tabBar.hw_badgeView.layer.borderWidth = 1;
    CGPoint badgePoint = CGPointMake(15, -3);
    self.tabBarController.tabBar.hw_badgePoint = badgePoint;
//    self.tabBarController.tabBar.hw_badgeSize = CGSizeMake(12, 12);
    self.tabBarController.tabBar.hw_badgeValue = [NSString stringWithFormat:@"%ld", self.index];
    [self.tabBarController.tabBar hw_showBadgeWithIndex:2];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
